﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

using Gift.DAL;
using Gift.Model;

namespace WebSite.admin.company
{
    public partial class companyPartner : BaseAdmin
    {
        readonly dalCompany theCompany = new dalCompany();
        public void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                base.ValidateLoginRule(Gift.Model.ENUM.ERule.CompanyPartner);
                if (Request.QueryString["action"] == "isprocess")
                {
                    SQLAccess.DoSql("update tblCompanyPartner set isProcess=1 where id=" + Request.QueryString["id"]);
                    base.Response.Write("<script language='javascript'>alert('设置成功');window.location.href='companyPartner.aspx';</script>");
                }
                this.BindGridView();
            }

        }
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.GridView1.PageIndex = this.ddlCurrentPage.SelectedIndex;
            this.BindGridView();
        }


        void BindGridView()
        {
            DataSet ds;
            ds = SQLAccess.GreatDs("select  Id, CompanyName, Linker, LinkWay, Description, IsProcess,PartnerWay,Email, case isProcess when 1 then '已处理' else '未处理' end as ProcessName from tblCompanyPartner order by IsProcess");

            if (ds.Tables.Count > 0)
            {
                this.GridView1.DataSource = ds.Tables[0].DefaultView;
                this.GridView1.DataBind();
                this.LblCurrentIndex.Text = "当前第 " + ((this.GridView1.PageIndex + 1)).ToString() + "页";
                this.LblPageCount.Text = "共 " + this.GridView1.PageCount.ToString() + "页";
                this.LblRecordCount.Text = "总计 " + ds.Tables[0].Rows.Count.ToString() + "个记录";
                if (ds.Tables[0].Rows.Count == 0)
                {
                    this.btnFirst.Visible = false;
                    this.btnPrev.Visible = false;
                    this.btnNext.Visible = false;
                    this.btnLast.Visible = false;
                    this.LblCurrentIndex.Visible = false;
                    this.LblPageCount.Visible = false;
                    this.LblRecordCount.Visible = false;
                }
                else if (this.GridView1.PageCount == 1)
                {
                    this.btnFirst.Visible = false;
                    this.btnPrev.Visible = false;
                    this.btnNext.Visible = false;
                    this.btnLast.Visible = false;
                }
                this.btnFirst.CommandName = "1";
                this.btnPrev.CommandName = (this.GridView1.PageIndex == 0) ? "1" : this.GridView1.PageIndex.ToString();
                this.btnNext.CommandName = (this.GridView1.PageCount == 1) ? this.GridView1.PageCount.ToString() : ((this.GridView1.PageIndex + 2)).ToString();
                this.btnLast.CommandName = this.GridView1.PageCount.ToString();
                this.ddlCurrentPage.Items.Clear();
                if (this.GridView1.PageCount > 0)
                {
                    for (int i = 1; i <= this.GridView1.PageCount; i++)
                    {
                        this.ddlCurrentPage.Items.Add(i.ToString());
                    }
                    this.ddlCurrentPage.SelectedIndex = this.GridView1.PageIndex;
                }
            }
        }

        protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
        {

        }




        protected void PagerButtonClick(object sender, EventArgs e)
        {
            this.GridView1.PageIndex = Convert.ToInt32(((LinkButton)sender).CommandName) - 1;
            this.BindGridView();
        }


        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if ((e.Row.RowType == DataControlRowType.Header) || (e.Row.RowType == DataControlRowType.DataRow))
            {
               
                    if (e.Row.RowType == DataControlRowType.DataRow)
                    {
                        e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=\"" + e.Row.Style["BACKGROUND-COLOR"] + "\"");
                        e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor=\"#efefef\"");
                    }
                    
                
            }
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {

        }
    }
}